﻿//----------------------------------------------------------------------------------------------------
// The Node lsit displays a vertical list of node types.
//----------------------------------------------------------------------------------------------------

package HG.Visual
{
	import flash.display.*;
	import flash.events.*;
	
	import HG.GameService;
	import HG.Visual.VisualNode;
	
	import HG.Debug;
	
	public class NodeList extends MovieClip
	{
		var m_newNodeCallback:Function;
		
		//----------------------------------------------------------------------------------------------------
		public function GameContainer() 
		{
			stop();
			loaderInfo.addEventListener(Event.INIT, onInit);
		}
  
  		//----------------------------------------------------------------------------------------------------
		public function onInit(e:Event)
		{
			
		}
		
		//----------------------------------------------------------------------------------------------------
		public function Populate(nodes:Vector.<String>)
		{
			var index:Number = 0;
			var listLength:Number = nodes.length;
			
			for (index = 0; index < listLength; ++index)
			{
				var type:String = nodes[index];
				
				var newNode:VisualNode = new VisualNode(type, index);
				addChild(newNode);
				
				newNode.scaleX = 0.75;
				newNode.scaleY = 0.75;
				
				newNode.x = 30;
				newNode.y = 40 + (index * 80);
				
				newNode.addEventListener(MouseEvent.MOUSE_DOWN, OnToolboxNode);
				
				newNode.SetVisible(true);
			}
		}
		
		//----------------------------------------------------------------------------------------------------
		private function OnToolboxNode(me:MouseEvent):void
		{
			m_newNodeCallback(me.currentTarget.GetType());
		}
		
		//----------------------------------------------------------------------------------------------------
		private function OnToolboxConnection(me:MouseEvent):void
		{
			m_newNodeCallback("Connection");
		}
		
		//----------------------------------------------------------------------------------------------------
		public function AttachAddNodeListener(callback:Function)
		{
			m_newNodeCallback = callback;
		}
	}
}









